package com.example.common.bean;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 用于在Spring容器中对Bean进行前后处理。通过实现BeanPostProcessor接口，可以对Spring管理的所有bean或特定bean进行增强处理，如修改bean实例对象信息、对当前bean对象创建代理等。
 */
@Component
public class PackBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("初始化之前处理逻辑...") ;
        // TODO
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName) ;
    }
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("初始化之后处理逻辑...") ;
        // TODO
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
